Skip to content

Add support for freebsd and various small fixes - #16

Merged
cmainas merged 9 commits into
mainfrom
feat/freebsd_init
Sep 12, 2026
Merged

cmainas merged 9 commits into
mainfrom
feat/freebsd_init

Conversation

@cmainas

@cmainas cmainas commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

This PR adds a platform-abstraction layer to urunit and a FreeBSD implementation of it, plus new configuration fields for passing the command arguments and the network config.

Until now urunit was Linux-only and relied on the Linux kernel to hand over things like the console, the network, and a writable root. However, this is not the case for FreeBSD and all the previously mentioned functionalities are now handled by urunit. The OS-specific pieces are moved behind a small platform interface. Linux and FreeBSD each provide their own implementation, and the shared logic stays free of per-OS branching.

On top of that, the configuration can be read from a regular file or straight from a raw device, since FreeBSD does not expose initrd in the same way as Linux.

cmainas added 9 commits March 17, 2026 09:46
Empty parentheses declare an unspecified argument list in C; use (void)
for the functions that take no arguments so the compiler checks call
sites. No behavioural change.

DEBUG_PRINT was declared variadic (fmt, ...) but its body never expands
the arguments, and invoking a variadic macro with no variadic argument is
not portable under -pedantic-errors. It is only ever used with a bare
format string, so drop the variadic parameter.

Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
Most applications expect a writable /tmp. Mount a tmpfs there in
mount_special_fs; urunit itself does not depend on it, so a failure is
logged but not fatal.

Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
Declare the platform-specific hooks in common.h (setup_console,
remount_root_rw, get_boot_var, read_raw_device, configure_network) and
the struct net_config they use, and provide their Linux implementations:
no-ops where the kernel already handles the concern (console, remount,
boot vars, network via ip=). This is the seam FreeBSD support plugs into.

The configuration may be handed to the guest as a tiny (virtio) block or
character device rather than a regular file. read_file_and_size now
detects that from st_mode and dispatches to the platform read_raw_device,
which reads the whole device; regular files keep the stdio path.

Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
When URUNIT_CONFIG / URUNIT_DEFROUTE are not in the process environment,
consult the kernel boot variables via get_boot_var (used when the kernel
passes parameters through its environment, e.g. FreeBSD as init).

Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
When urunit is started with no command line (e.g. by the FreeBSD kernel
as init), take the application and its arguments from the UCS/UCE section
of the configuration (ARC count + verbatim ARV arguments).

Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
Implement the platform hooks for FreeBSD in src/freebsd.c (console via
/dev/console, kenv boot vars, raw virtio config device, network via the
routing socket, root remount, tmpfs, subreaper via procctl, reboot) and
add the Makefile rule that builds it when TARGET_OS is FreeBSD.

Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
Parse the UNS/UNE section (IP/GW/MSK) and hand it to the platform
configure_network hook, for guests that cannot get the network from the
kernel command line. No-op on Linux (network comes from ip=).

Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
Describe the UCS/UCE application-command section and the UNS/UNE network
section of the configuration file in the README.

Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com>
@cmainas
cmainas force-pushed the feat/freebsd_init branch 2 times, most recently from 0ea3a99 to 6e63bda Compare September 12, 2026 05:48
@cmainas
cmainas merged commit 86913f1 into main Sep 12, 2026
5 checks passed
@cmainas
cmainas deleted the feat/freebsd_init branch September 12, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant